package com.yc.snack.dao.impl;

import java.util.List;

import com.yc.snack.dao.ITypeInfoDao;
import com.yc.snack.entity.TypeInfo;
import com.yc.snack.dao.util.DBUtil;

public class TypeInfoDaoImpl implements ITypeInfoDao {

	@Override
	public int getTotal() {
		DBUtil db  = new DBUtil();
		String sql = "select count(tno) from goodstype";

		return Integer.parseInt(db.findStr(sql));
	}

	@Override
	public int add(TypeInfo tf) {
		DBUtil db  = new DBUtil();
		String sql = "insert into goodstype values(0, ?, 1)";
		return db.update(sql, tf.getTname());
	}

	@Override
	public List<TypeInfo> finds() {
		DBUtil db  = new DBUtil();
		String sql = "select tno ,tname from goodstype where status != 0";	
		return db.finds(TypeInfo.class, sql);
	}

	@Override
	public List<TypeInfo> findByPage(int page, int rows) {
		DBUtil db  = new DBUtil();
		String sql = "select tno,tname,status from goodstype order by tno limit ?,?";
		return db.finds(TypeInfo.class,sql,(page-1) * rows,rows);
	}

	

}
